def index(request):
 if len(Teacher.objects.all())==0:
    #print(Teacher.objects.all())
    file0=open(r"E:\Project\PythonProject\pythonProject1\Work3\ex.txt","r",encoding='utf-8')
    lines=file0.readlines()
    Tlist = []  # 最终输出的数组
    lenT = 1  # 记录Tlist的长度
    for line in lines:
        list=line.rstrip().split(",")
        t=0 # 标记作用，为了去除每个值的空格
        for l in list:
            newl=l.strip()
            list[t]=newl
            t+=1
        if len(list)==1:
            Tlist[lenT-1]+=list[0]
        elif len(list)==8:
            Tlist==list
            lenT=8
        else:
            Tlist[len(Tlist)-1]+=list[0]
            Tlist.extend(list[1:])
            lenT=len(Tlist)
        if len(Tlist)==8:
           Teacher.objects.create(name=Tlist[0],gender=Tlist[1],college=Tlist[2],major=Tlist[3],direction=Tlist[4],email=Tlist[5],intro=Tlist[6],photo=Tlist[7])
           Tlist = []
           lenT = 1
 ls=Teacher.objects.all()
 #print(ls)
 context={"teachers_list":ls}
 return render(request,"index.html",context)